package com.rs;

import com.common.compoent.PrintWriter;
import com.ribbon.CustomRuleConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @Author Str
 * @Date 2022/1/10 14:45
 * @Description :
 */
@SpringBootApplication
@EnableEurekaClient
// @EnableDiscoveryClient是使用DiscoveryClient的前提
@EnableDiscoveryClient
// 用于指定自定义负载均衡策略，name（服务名），configuration（负载均衡配置类）
// 指定这个服务使用自定的负载均衡策略
@RibbonClient(name = "DEPT-PROVIDER", configuration = CustomRuleConfig.class)
public class RibbonConsumer9301Application {
    @LoadBalanced  // 负载均衡
    @Bean
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    public static void main(String[] args) {
        SpringApplication.run(RibbonConsumer9301Application.class, args);
        PrintWriter.prtMark("Ribbon客户端已启动");
    }
}
